package cn.openea.perpartner.link.handler.exception;

import cn.openea.perpartner.common.core.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author ysk
 * @version 1.0.1
 * @Description 统一处理Controller抛出的异常
 * @createTime 2023年05月23日 17:01:00
 */
@RestControllerAdvice(annotations = Controller.class)
@Slf4j
public class LinkWebSiteExceptionHandler {

    @ExceptionHandler(value = ServiceException.class)
    public ModelAndView exceptionHandler(ServiceException e) {
        log.error("异常信息为:{},异常类型为:{}", e.getMessage(), e.getClass());
        ModelAndView view = new ModelAndView();
        view.setViewName("404");
        return view;
    }

    @ExceptionHandler(value = Exception.class)
    public ModelAndView unknownException(Exception e) {
        ModelAndView view = new ModelAndView();
        log.error("异常信息为:{},异常类型为:{}", e.getMessage(), e.getClass());
        view.setViewName("404");
        return view;
    }

}
